package com.yanze.schoolinformation.utils;

/**
 * 字符串判断工具类
 * Created by MrZheng on 2017/11/21.
 */

public class StringUtils {

    //判断空
    public static boolean isEmpty(String str) {
        if (str == null) {
            return true;
        }
        return str.isEmpty();
    }

    //判断是否是手机号
    public static boolean isPhoneNumber(String num) {
        String regiex = "^1[34578]{1}\\d{9}$";
        return num.matches(regiex);
    }

    //判断短信验证码
    public static boolean isSmsCode(String sms) {
        if (sms.length() == 6) {
            return true;
        }
        return false;
    }

    //判断身份证格式
    public static boolean isIdCard(String idCard) {
        String regiex1 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{4}$";
        String regiex2 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$";
        boolean iscard1 = idCard.matches(regiex1);
        boolean iscard2 = idCard.matches(regiex2);
        if (iscard1 || iscard2) {
            return true;
        }
        return false;
    }

    //判断邮箱格式
    public static boolean isEmail(String email) {
        String regies = "^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+";
        boolean isEmail = email.matches(regies);
        return isEmail;
    }

    //判断密码格式
    public static boolean isPwd(String pwd) {
        if (pwd.length() < 6 || pwd.length() > 20) {
            return false;
        }
        return true;
    }

    //昵称校验
    public static boolean isNick(String nick) {
        if (nick.length() > 16) {
            return false;
        }
        return true;
    }

    /**
     * 显示发送到的手机号码
     *
     * @param number 181 6869 1092
     *               012 3456 78910
     */
    public static String showNumber(String number) {
        if (number.length() != 11) {
            return number;
        }
        String head = number.substring(0, 3);
        String end = number.substring(7, 11);
        String newNumber = head + "****" + end;
        return newNumber;
    }
}
